package client.control;


import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import net.miginfocom.swing.MigLayout;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Color;
import javax.swing.JPasswordField;
import javax.swing.JFormattedTextField;

import shop.local.valueobjects.ArtikelListe;
import shop.local.valueobjects.Warenkorb;


public class BestandDialog extends JDialog {

	private final JPanel contentPanel = new JPanel();
	protected JTextField txtBestand;
	protected int bestand;
	private MainScroll scroll; 
	

	/**
	 * Launch the application.
	 */
/*	public static void main(String[] args) {
		try {
			LoginDialog dialog = new LoginDialog(main);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}*/

	/**
	 * Create the dialog.
	 * @param aNr 
	 */
	public BestandDialog(MainScroll scrolly, final int aNr) {
		this.scroll = scrolly;
		setResizable(false);
		setBounds(100, 100, 350, 150);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new MigLayout("", "[][grow]", "[][][]"));
		{
			JLabel lblUsername = new JLabel("Bestand");
			contentPanel.add(lblUsername, "cell 0 0,alignx trailing");
		}
		{
			txtBestand = new JTextField();
			contentPanel.add(txtBestand, "cell 1 0,growx");
			txtBestand.setColumns(10);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("in Warenkorb legen");
				okButton.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent m) {
						String bestandString = txtBestand.getText();
						int bestand = Integer.parseInt(bestandString);
						scroll.setzeBestandsVeraenderung(bestand);
						dispose();
					}
					});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Abbrechen");
				cancelButton.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent arg0) {
						dispose();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
		
		this.setModal(true);
        this.setAlwaysOnTop(true);
		this.setVisible(true);
	}
	
	public int getBestand() {
		return this.bestand;
	}

}
